package com.wang.lotterysystem.dao.mapper;

import com.wang.lotterysystem.dao.dataobject.prize.PrizeDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PrizeMapper {
    @Insert("insert into prize (name, description, price, image_url) " +
            "values (#{name},#{description},#{price},#{imageUrl})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")//把该行在id列对应的值赋回PrizeDO对象中的id属性中
    int insert(PrizeDO prizeDO);

    @Select("select count(1) from prize")
    int count();
    @Select("select id, gmt_create, gmt_modified, name, description, price, image_url" +
            " from prize order by id desc " +
            "limit #{pageSize} offset #{offset}")
    List<PrizeDO> queryPrizesByPage(Integer offset,Integer pageSize);

    @Select("<script> " +
            "select id from prize where id in " +
            "<foreach collection = 'prizeId' item = 'id' open = '(' close = ')' separator = ','> " +
            "#{id} " +
            "</foreach> " +
            "</script> ")
    List<Long> batchExistByIds(List<Long> prizeId);

    @Select("<script> " +
            "select id, gmt_create, gmt_modified, name, description, price, image_url from prize where id in " +
            "<foreach collection = 'prizeId' item = 'id' open = '(' close = ')' separator = ','> " +
            "#{id} " +
            "</foreach> " +
            "</script> ")
    List<PrizeDO> selectByIdList(List<Long> prizeId);

    @Select("select * from prize where id = #{prizeId}")
    PrizeDO selectById(Long prizeId);
}